package com.example.service.serviceImple;

import com.example.mapper.one.TreeMapper;
import com.example.pojo.Tree;
import com.example.service.TreeService;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class TreeServiceImple implements TreeService {

    @Resource
    private TreeMapper treeMapper;

    @Override
    public List<Tree> getChildTree(Integer ancestorId) {
        List<Tree> list = new ArrayList<Tree>();
        list = treeMapper.getChildTree(ancestorId);
        for(int i = 0;i < list.size();i++){
            List<Tree> majorList = new ArrayList<Tree>();
            majorList = treeMapper.getChildTree(list.get(i).getLabelId());
            for(int j = 0;j < majorList.size();j++){
                List<Tree> teamList = new ArrayList<Tree>();
                teamList = treeMapper.getChildTree(majorList.get(j).getLabelId());
                majorList.get(j).setChildren(teamList);
            }
            list.get(i).setChildren(majorList);
        }
        return list;
    }

    @Override
    public List<Tree> getGradeList() {
        List<Tree> list = new ArrayList<Tree>();
        list = treeMapper.getChildTree(0);
        return list;
    }
}
